﻿#region Using Statements
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Storage;
#endregion  

namespace Ramparts
{
    class Boat : StatefulGameComponent
    {

        AnimatedSprite dyingAnimation;
        AnimatedSprite movingAnimation;

         public Boat(int x, int y, SceneManager inSceneManager) : base(new Vector2(x,y), inSceneManager)
          {

            this.sceneManager = sceneManager;
            this.position = new Vector2(x, y);

            currentHitPoints = totalHitPoints = 1000;
           
            speed = 3;
            bearing = (float)-(3 * Math.PI / 4);
            
            // Sinking Boat Animation
            AnimatedSprite dyingAnimation = new AnimatedSprite("Content\\iso_objects", sceneManager);
            dyingAnimation.addFrame(new Rectangle(0, 40, 40, 40));
            dyingAnimation.addFrame(new Rectangle(40, 40, 40, 40));
            dyingAnimation.addFrame(new Rectangle(80, 40, 40, 40));
            dyingAnimation.addFrame(new Rectangle(120, 40, 40, 40));
            dyingAnimation.addFrame(new Rectangle(160, 40, 40, 40));
            dyingAnimation.addFrame(new Rectangle(200, 40, 40, 40));
            dyingAnimation.addFrame(new Rectangle(240, 40, 40, 40));

            // Sinking Boat Animation
            AnimatedSprite damagedAnimation = new AnimatedSprite("Content\\iso_objects", sceneManager);
            damagedAnimation.addFrame(new Rectangle(0, 80, 40, 40));
            damagedAnimation.addFrame(new Rectangle(40, 80, 40, 40));
            damagedAnimation.addFrame(new Rectangle(80, 80, 40, 40));
            damagedAnimation.addFrame(new Rectangle(120, 80, 40, 40));
            damagedAnimation.addFrame(new Rectangle(160, 80, 40, 40));
            damagedAnimation.addFrame(new Rectangle(200, 80, 40, 40));
            damagedAnimation.addFrame(new Rectangle(240, 80, 40, 40));

            movingAnimation = new AnimatedSprite("Content\\iso_objects", sceneManager);
            movingAnimation.addFrame(new Rectangle(0, 40, 40, 40));

            DyingState dyingState = new DyingState(dyingAnimation, this);
            MoveOnBearingState moveState = new MoveOnBearingState(movingAnimation, this);
            MoveOnBearingState damagedState = new MoveOnBearingState(damagedAnimation, this);

            states.Add(0, moveState);
            states.Add(1, damagedState);
            states.Add(2, dyingState);

            currentState = 0;
            
        }

         public override void Draw()
         {
             states[currentState].draw();
         }

        public override void Update(GameTime gameTime)
        {

            currentHitPoints--;

            if (currentHitPoints < 500 && currentHitPoints > 0)
            {
                currentState = 1;
                states[currentState].begin();
            }
            
            if (currentHitPoints <= 0)
            {
                currentState = 2;
                states[currentState].begin();
            }
            // Update the current state
            states[currentState].update(gameTime);
            Console.WriteLine(currentState);
 
        }
     
    }

}
